package com.study.living.camera;

import android.content.Context;

public abstract class AbsCamera {

    /**
     * 前置摄像头
     * 参照camera2的CameraMetadata类
     */
    public static final int FACING_FRONT = 0;

    /**
     * 后置摄像头
     * 参照camera2的CameraMetadata类
     */
    public static final int FACING_BACK = 1;

    /**
     * 外接摄像头
     * 参照camera2的CameraMetadata类
     */
    public static final int FACING_EXTERNAL = 2;


    public static final int FLASH_OFF = 0;
    public static final int FLASH_ON = 1;
    public static final int FLASH_TORCH = 2;
    public static final int FLASH_AUTO = 3;
    public static final int FLASH_RED_EYE = 4;

    protected Context mAppContext;
    protected TexturePreview mPreview;

    protected int mFacing = FACING_BACK;
    protected boolean mAutoFocus = true;
    protected int mFlash;

    /**
     * 当没有对应朝向的相机时，自动选择一个相机
     */
    protected boolean autoSelectWhenNoFacingCamera = true;

    public AbsCamera(Context context, TexturePreview texturePreview) {
        this.mAppContext = context.getApplicationContext();
        this.mPreview = texturePreview;
    }

    public void setFacing(int facing) {
        if (mFacing == facing){
            return;
        }
        mFacing = facing;
    }

    public int getFacing() {
        return mFacing;
    }

    public void setAutoFocus(boolean autoFocus) {
        if (mAutoFocus == autoFocus){
            return;
        }
        this.mAutoFocus = autoFocus;
    }

    public void setFlash(int flash) {
        if (mFlash == flash){
            return;
        }
        this.mFlash = flash;
    }

    /**
     * 开启相机，并预览
     */
    public abstract boolean start();

    /**
     * 关闭相机，停止预览
     */
    public abstract void stop();

    /**
     * 选择相机
     */
    public abstract boolean chooseCameraByFacing();

    /**
     * 开启相机
     */
    public abstract void openCamera();

    /**
     * 相机是否已开启
     */
    public abstract boolean isCameraOpened();
}
